package com.example.demo.controller;

import com.example.demo.factory.ProcessorFactory;
import com.example.demo.factory.service.ProcessHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author mdl
 * @date 2020/4/3 13:17
 */
@Controller
@Slf4j
public class ExampleController {

    @Autowired
    private ProcessorFactory processorFactory;

    @RequestMapping(value ="/home", method = RequestMethod.GET)
    @ResponseBody
    public String home(){
        return "你好，Spring Boot";
    }

    @RequestMapping(value ="/pay", method = RequestMethod.GET)
    @ResponseBody
    public String pay(@RequestParam("payType") String payType,
                      @RequestParam("params") String params){

        ProcessHandle processHandle = processorFactory.getProcessHandleByKey(payType);
        if(null != processHandle){
            processHandle.dealProcess(params);
        }else{
            log.error("不支持的支付方式，支付参数: " + payType);
        }

        return "你好，Spring Boot";
    }

}
